/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

/**
 *
 * @author Yanick
 */
import java.sql.*;
import javax.swing.JLabel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Yanick
 */
public class highscore extends javax.swing.JFrame {

    /**
     * Creates new form highscore
     */
    public highscore() {
        initComponents();
    }

    @SuppressWarnings("unchecked")

    private void initComponents() {

    	jPanel1 = new javax.swing.JPanel();
    	labels = new JLabel[20];
        player1 = new javax.swing.JLabel();
        player2 = new javax.swing.JLabel();
        player3 = new javax.swing.JLabel();        
        player4 = new javax.swing.JLabel();
        player5 = new javax.swing.JLabel();        
        player6 = new javax.swing.JLabel();        
        player7 = new javax.swing.JLabel();
        player8 = new javax.swing.JLabel();
        player9 = new javax.swing.JLabel();
        player10 = new javax.swing.JLabel();
        points1 = new javax.swing.JLabel();
        points2 = new javax.swing.JLabel();
        points3 = new javax.swing.JLabel();
        points4 = new javax.swing.JLabel();
        points5 = new javax.swing.JLabel();
        points6 = new javax.swing.JLabel();       
        points7 = new javax.swing.JLabel();
        points8 = new javax.swing.JLabel();
        points9 = new javax.swing.JLabel(); 
        points10 = new javax.swing.JLabel();
        
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        
        labels[0] = player1;
        labels[1] = points1;
        labels[2] = player2;
        labels[3] = points2;
        labels[4] = player3;
        labels[5] = points3;
        labels[6] = player4;
        labels[7] = points4;
        labels[8] = player5;
        labels[9] = points5;
        labels[10] = player6;
        labels[11] = points6;
        labels[12] = player7;
        labels[13] = points7;
        labels[14] = player8;
        labels[15] = points8;
        labels[16] = player9;
        labels[17] = points9;
        labels[18] = player10;
        labels[19] = points10;
 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));

 	   try {	

	        // mySQL Anbindung
	        Class.forName("com.mysql.jdbc.Driver");

	        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/highscore?user=root&password=");
	        
	        Statement stmt = connection.createStatement();

	        String query = "SELECT user, points FROM highscore ORDER BY points DESC;";

	        ResultSet rs = stmt.executeQuery(query);

	        ResultSetMetaData rsmd = rs.getMetaData();
	        
	        int noColumns = rsmd.getColumnCount();
	        for (int i = 1; i <= noColumns; i++){
	        }
	        System.out.println();

	        int g = 0;
	        
	        while (rs.next()) { 
	        	
	        	
	        	for (int i = 1; i <= noColumns; i++){
	        		
	        		Object obj = rs.getObject(i);
	        		labels[g].setText(obj.toString());
	        		g = g + 1;	

	       }
	        }

	        stmt.close();

	        if (connection != null)
	          connection.close();

	      }
	          
	      catch (Exception ex) {
	   	System.err.println("Error" + ex.getMessage());
	      }
        
        
        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel23.setText("Player");

        jLabel24.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel24.setText("Punkte");

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel2.setText("Highscore-Tabelle");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(34, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(33, 33, 33))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(167, 167, 167)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel23)
                    .addComponent(player9)
                    .addComponent(player8)
                    .addComponent(player10)
                    .addComponent(player6)
                    .addComponent(player5)
                    .addComponent(player7)
                    .addComponent(player4)
                    .addComponent(player3)
                    .addComponent(player2)
                    .addComponent(player1))
                .addGap(111, 111, 111)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(points9)
                    .addComponent(points8)
                    .addComponent(points10)
                    .addComponent(points6)
                    .addComponent(points5)
                    .addComponent(points7)
                    .addComponent(points4)
                    .addComponent(points3)
                    .addComponent(points2)
                    .addComponent(points1)
                    .addComponent(jLabel24))
                .addContainerGap(217, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jLabel24))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(points1)
                        .addGap(18, 18, 18)
                        .addComponent(points2)
                        .addGap(18, 18, 18)
                        .addComponent(points3)
                        .addGap(18, 18, 18)
                        .addComponent(points4)
                        .addGap(18, 18, 18)
                        .addComponent(points5)
                        .addGap(18, 18, 18)
                        .addComponent(points6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(points7)
                        .addGap(18, 18, 18)
                        .addComponent(points8)
                        .addGap(18, 18, 18)
                        .addComponent(points9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(points10))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(player1)
                        .addGap(18, 18, 18)
                        .addComponent(player2)
                        .addGap(18, 18, 18)
                        .addComponent(player3)
                        .addGap(18, 18, 18)
                        .addComponent(player4)
                        .addGap(18, 18, 18)
                        .addComponent(player5)
                        .addGap(18, 18, 18)
                        .addComponent(player6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(player7)
                        .addGap(18, 18, 18)
                        .addComponent(player8)
                        .addGap(18, 18, 18)
                        .addComponent(player9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(player10)))
                .addContainerGap(46, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(highscore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(highscore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(highscore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(highscore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new highscore().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private JLabel[]labels;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel player1;
    private javax.swing.JLabel player10;
    private javax.swing.JLabel player2;
    private javax.swing.JLabel player3;
    private javax.swing.JLabel player4;
    private javax.swing.JLabel player5;
    private javax.swing.JLabel player6;
    private javax.swing.JLabel player7;
    private javax.swing.JLabel player8;
    private javax.swing.JLabel player9;
    private javax.swing.JLabel points1;
    private javax.swing.JLabel points10;
    private javax.swing.JLabel points2;
    private javax.swing.JLabel points3;
    private javax.swing.JLabel points4;
    private javax.swing.JLabel points5;
    private javax.swing.JLabel points6;
    private javax.swing.JLabel points7;
    private javax.swing.JLabel points8;
    private javax.swing.JLabel points9;
    // End of variables declaration
}
